package bc.swim2.ejb.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@NamedQueries({
		/**
		 * Query that returns the Ability getting like parameter the Id
		 */
		@NamedQuery(name = "Ability.getAbilityById", query = "SELECT a FROM Ability a WHERE a.id = :id"),
		/**
		 * Query that returns the Ability getting like parameter the name
		 */
		@NamedQuery(name = "Ability.getAbilityByName", query = "SELECT a FROM Ability a WHERE a.name = :name"),
		/**
		 * Query that returns the Id getting like parameter the name
		 */
		@NamedQuery(name = "Ability.getIdByName", query = "SELECT a.id FROM Ability a WHERE a.name = :name"),
		/**
		 * Query that returns the list of abilities possessed by an user
		 */
		@NamedQuery(name = "Ability.getAbilityByUserId", query = "SELECT a FROM RegisteredUser ru, Ability a WHERE ru.id = :id AND a MEMBER OF ru.abilityPossessed"),
		/**
		 * Query that returns the name getting like parameter the Id
		 */
		@NamedQuery(name = "Ability.getNameById", query = "SELECT a.name FROM Ability a WHERE a.id = :id"),
		@NamedQuery(name = "Ability.getAbilityList", query = "SELECT a FROM Ability a") })
@Entity
@Table(name = "ability")
public class Ability implements Serializable {

	/**
	 * Default constructor
	 */
	public Ability() {
	}

	/**
	 * constructor with all the parameters
	 * 
	 * @param id
	 * @param name
	 */
	public Ability(int id, String name) {
		this.id = id;
		this.name = name;
	}

	private static final long serialVersionUID = -375687273137022226L;

	/**
	 * Identification attribute for the entity Ability
	 **/
	@Id
	@GeneratedValue
	@Column(name = "Id", nullable = false)
	int id;

	/**
	 * Getter method for id
	 * 
	 * @return id
	 */
	public int getId() {
		return id;
	}

	/**
	 * Setter method for id
	 * 
	 * @param id
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Attribute that represent the name of the ability
	 */
	@Column(name = "Name", nullable = false)
	String name;

	/**
	 * Getter method for name
	 * 
	 * @return name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Setter method for name
	 * 
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * List of possessor users of the ability
	 */
	@ManyToMany(mappedBy = "abilityPossessed")
	private Set<RegisteredUser> usersPossessor;

	/**
	 * Getter method for list of users possessors
	 * 
	 * @return usersPossessor
	 */

	public Set<RegisteredUser> getUsersPossessor() {
		return usersPossessor;
	}

	/**
	 * Setter method for list of users possessors
	 * 
	 * @param usersPossessor
	 */
	public void setUsersPossessor(Set<RegisteredUser> usersPossessor) {
		this.usersPossessor = usersPossessor;
	}

}
